package cn.yza.Kotlin.`01`

import java.lang.IllegalArgumentException

/**
@author Honglixi
@create 2022-05-26 17:39
 */
interface Expr
class Num(val value: Int) : Expr
class Sum(val left: Expr, val right: Expr) : Expr
fun eval(e: Expr) : Int =
        if (e is Num)
            e.value
        else if (e is Sum)
            eval(e.left) +eval(e.right)
        else
            throw IllegalArgumentException("Unknown expression")

fun main() {
    println(eval(Sum(Num(1), Num(2))))
}